﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace Senthil.Mobile.WhereAmI
{
    [Serializable]
    public class RoutePoint : IComparable<RoutePoint>
    {
        Location location;
        TimeSpan timeFromPreviousRoutePoint;

        int relativeIndexInRoute;

        public RoutePoint(Location location, TimeSpan timeFromPreviousRoutePoint)
        {
            this.Location = location;

            this.timeFromPreviousRoutePoint = timeFromPreviousRoutePoint;
        }

        public RoutePoint()
        { }

        [XmlElement("LocationId")]
        public Guid LocationId
        {
            get;
            set;
        }

        [XmlIgnore]
        public Location Location
        {
            get { return location; }
            internal set { location = value; LocationId = value.Id; }
        }

        [XmlIgnore]
        public int RelativeIndexInRoute
        {
            get { return relativeIndexInRoute; }
            set { relativeIndexInRoute = value; }
        }

        [XmlIgnore]
        public TimeSpan TimeFromPreviousRoutePoint
        {
            get { return timeFromPreviousRoutePoint; }
            set { timeFromPreviousRoutePoint = value; }
        }

        [XmlElement("TimeOffset")]
        public string SerializedTimeFromPreviousRoutePoint
        {
            get { return timeFromPreviousRoutePoint.ToString(); }
            set { timeFromPreviousRoutePoint = TimeSpan.Parse(value); }
        }

        internal RoutePoint Next { get; set; }
        internal RoutePoint Previous { get; set; }

        #region IComparable<RoutePoint> Members

        public int CompareTo(RoutePoint other)
        {
            return this.RelativeIndexInRoute.CompareTo(other.RelativeIndexInRoute);
        }

        #endregion
    }
}
